package view;

import java.awt.EventQueue;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.Color;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import control.SudokuGenerator;
import control.SudokuLoeser;
import model.Sudoku;

import java.util.Random;

/* Es fehlt noch:
 *  - leere Felder farbig machen
 *  - Feedback durch Keks
 * 
 */

public class Tutorial {

	private JFrame frame;
	private int intPosition = 0;

	byte arrayUebung[] = new byte[9];
	byte arrayGrossesFeld[][] = new byte[9][9];

	final JButton[][] btnFeld = new JButton[9][9];
	final JButton[] btnZahlen = new JButton[9];

	private int aufgabe = 0;
	int luechenInGrFeld = 0;
	byte arrayGeweahlt[] = new byte[2];
	Random generator = new Random();

	JLabel labelText = new JLabel("");
	JButton buttonWeiter = new JButton(new ImageIcon(Tutorial.class.getResource("/Bilder/Weiter-Button.gif")));
	JButton buttonZurueck = new JButton(new ImageIcon(Tutorial.class.getResource("/Bilder/Zurueck-Button.gif")));
	JButton buttonEnde = new JButton("");
	
	private Sudoku sudoku;

	private byte byteSpaltenWert;

	private byte byteZeilenWert;

	final String stoneClickSound = "/Sounds/StoneClick.wav";

	final String wonGame = "/Sounds/GewonnenesSpiel.wav";

	public JFrame getJFrame() {
		return frame;
	}

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Tutorial window = new Tutorial();
					window.frame.setVisible(true);
					window.frame.setBounds(0, 0, 1024, 768);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public Tutorial() {
		initialize();
	}

	private void initialize() {

		try {
			for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (Exception e) {
			// Wenn Nimbus nicht vorhanden, kann man das Look & Feel noch
			// aendern
		}

		frame = new JFrame();
		frame.setResizable(false);
		frame.setBounds(0, 0, 1024, 768);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		frame.setVisible(true);

		// Keks einf�gen
		JLabel labelBildKeks = new JLabel("");
		labelBildKeks.setIcon(new ImageIcon(GrundGUI.class
				.getResource("/Bilder/Keks-fuer-das-TutorialKlein.gif")));
		labelBildKeks.setBounds(602, 84, 426, 344);
		frame.getContentPane().add(labelBildKeks);

		// Label f�r Erkl�rungen
		labelText.setFont(new Font("Tahoma", Font.PLAIN, 22));
		labelText.setVerticalAlignment(SwingConstants.TOP);
		labelText.setBounds(10, 11, 643, 221);
		frame.getContentPane().add(labelText);

		// Buttons zur Ausgabe des Sudokus
		// Bei Klick auf einen Button, diesen als gew�hlt festlegen
		// Reihe 1
		JButton button1_1 = new JButton("");
		button1_1.setBackground(Color.WHITE);
		button1_1.setBounds(57, 244, 50, 50);
		frame.getContentPane().add(button1_1);
		button1_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][0] = button1_1;

		JButton button1_2 = new JButton("");
		button1_2.setBackground(Color.WHITE);
		button1_2.setBounds(108, 244, 50, 50);
		frame.getContentPane().add(button1_2);
		button1_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][1] = button1_2;

		JButton button1_3 = new JButton("");
		button1_3.setBackground(Color.WHITE);
		button1_3.setBounds(157, 244, 50, 50);
		frame.getContentPane().add(button1_3);
		button1_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][2] = button1_3;

		JButton button1_4 = new JButton("");
		button1_4.setBackground(Color.WHITE);
		button1_4.setBounds(210, 244, 50, 50);
		frame.getContentPane().add(button1_4);
		button1_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][3] = button1_4;

		JButton button1_5 = new JButton("");
		button1_5.setBackground(Color.WHITE);
		button1_5.setBounds(260, 244, 50, 50);
		frame.getContentPane().add(button1_5);
		button1_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][4] = button1_5;

		JButton button1_6 = new JButton("");
		button1_6.setBackground(Color.WHITE);
		button1_6.setBounds(310, 244, 50, 50);
		frame.getContentPane().add(button1_6);
		button1_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][5] = button1_6;

		JButton button1_7 = new JButton("");
		button1_7.setBackground(Color.WHITE);
		button1_7.setBounds(363, 244, 50, 50);
		frame.getContentPane().add(button1_7);
		button1_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][6] = button1_7;

		JButton button1_8 = new JButton("");
		button1_8.setBackground(Color.WHITE);
		button1_8.setBounds(413, 244, 50, 50);
		frame.getContentPane().add(button1_8);
		button1_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][7] = button1_8;

		JButton button1_9 = new JButton("");
		button1_9.setBackground(Color.WHITE);
		button1_9.setBounds(463, 244, 50, 50);
		frame.getContentPane().add(button1_9);
		button1_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[0][8] = button1_9;

		// Reihe 2
		JButton button2_1 = new JButton("");
		button2_1.setBackground(Color.WHITE);
		button2_1.setBounds(57, 293, 50, 50);
		frame.getContentPane().add(button2_1);
		button2_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][0] = button2_1;

		JButton button2_2 = new JButton("");
		button2_2.setBackground(Color.WHITE);
		button2_2.setBounds(108, 293, 50, 50);
		frame.getContentPane().add(button2_2);
		button2_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][1] = button2_2;

		JButton button2_3 = new JButton("");
		button2_3.setBackground(Color.WHITE);
		button2_3.setBounds(157, 293, 50, 50);
		frame.getContentPane().add(button2_3);
		button2_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][2] = button2_3;

		JButton button2_4 = new JButton("");
		button2_4.setBackground(Color.WHITE);
		button2_4.setBounds(210, 293, 50, 50);
		frame.getContentPane().add(button2_4);
		button2_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][3] = button2_4;

		JButton button2_5 = new JButton("");
		button2_5.setBackground(Color.WHITE);
		button2_5.setBounds(260, 293, 50, 50);
		frame.getContentPane().add(button2_5);
		button2_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][4] = button2_5;

		JButton button2_6 = new JButton("");
		button2_6.setBackground(Color.WHITE);
		button2_6.setBounds(310, 293, 50, 50);
		frame.getContentPane().add(button2_6);
		button2_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][5] = button2_6;

		JButton button2_7 = new JButton("");
		button2_7.setBackground(Color.WHITE);
		button2_7.setBounds(363, 293, 50, 50);
		frame.getContentPane().add(button2_7);
		button2_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][6] = button2_7;

		JButton button2_8 = new JButton("");
		button2_8.setBackground(Color.WHITE);
		button2_8.setBounds(413, 293, 50, 50);
		frame.getContentPane().add(button2_8);
		button2_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][7] = button2_8;

		JButton button2_9 = new JButton("");
		button2_9.setBackground(Color.WHITE);
		button2_9.setBounds(463, 293, 50, 50);
		frame.getContentPane().add(button2_9);
		button2_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[1][8] = button2_9;

		// Reihe 3
		JButton button3_1 = new JButton("");
		button3_1.setBackground(Color.WHITE);
		button3_1.setBounds(57, 343, 50, 50);
		frame.getContentPane().add(button3_1);
		button3_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][0] = button3_1;

		JButton button3_2 = new JButton("");
		button3_2.setBackground(Color.WHITE);
		button3_2.setBounds(108, 343, 50, 50);
		frame.getContentPane().add(button3_2);
		button3_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][1] = button3_2;

		JButton button3_3 = new JButton("");
		button3_3.setBackground(Color.WHITE);
		button3_3.setBounds(157, 343, 50, 50);
		frame.getContentPane().add(button3_3);
		button3_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][2] = button3_3;

		JButton button3_4 = new JButton("");
		button3_4.setBackground(Color.WHITE);
		button3_4.setBounds(210, 343, 50, 50);
		frame.getContentPane().add(button3_4);
		button3_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][3] = button3_4;

		JButton button3_5 = new JButton("");
		button3_5.setBackground(Color.WHITE);
		button3_5.setBounds(260, 343, 50, 50);
		frame.getContentPane().add(button3_5);
		button3_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][4] = button3_5;

		JButton button3_6 = new JButton("");
		button3_6.setBackground(Color.WHITE);
		button3_6.setBounds(310, 343, 50, 50);
		frame.getContentPane().add(button3_6);
		button3_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][5] = button3_6;

		JButton button3_7 = new JButton("");
		button3_7.setBackground(Color.WHITE);
		button3_7.setBounds(363, 343, 50, 50);
		frame.getContentPane().add(button3_7);
		button3_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][6] = button3_7;

		JButton button3_8 = new JButton("");
		button3_8.setBackground(Color.WHITE);
		button3_8.setBounds(413, 343, 50, 50);
		frame.getContentPane().add(button3_8);
		button3_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][7] = button3_8;

		JButton button3_9 = new JButton("");
		button3_9.setBackground(Color.WHITE);
		button3_9.setBounds(463, 343, 50, 50);
		frame.getContentPane().add(button3_9);
		button3_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[2][8] = button3_9;

		// Reihe 4
		JButton button4_1 = new JButton("");
		button4_1.setBackground(Color.WHITE);
		button4_1.setBounds(57, 396, 50, 50);
		frame.getContentPane().add(button4_1);
		button4_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][0] = button4_1;

		JButton button4_2 = new JButton("");
		button4_2.setBackground(Color.WHITE);
		button4_2.setBounds(108, 396, 50, 50);
		frame.getContentPane().add(button4_2);
		button4_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][1] = button4_2;

		JButton button4_3 = new JButton("");
		button4_3.setBackground(Color.WHITE);
		button4_3.setBounds(157, 396, 50, 50);
		frame.getContentPane().add(button4_3);
		button4_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][2] = button4_3;

		JButton button4_4 = new JButton("");
		button4_4.setBackground(Color.WHITE);
		button4_4.setBounds(210, 396, 50, 50);
		frame.getContentPane().add(button4_4);
		button4_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][3] = button4_4;

		JButton button4_5 = new JButton("");
		button4_5.setBackground(Color.WHITE);
		button4_5.setBounds(260, 396, 50, 50);
		frame.getContentPane().add(button4_5);
		button4_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][4] = button4_5;

		JButton button4_6 = new JButton("");
		button4_6.setBackground(Color.WHITE);
		button4_6.setBounds(310, 396, 50, 50);
		frame.getContentPane().add(button4_6);
		button4_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][5] = button4_6;

		JButton button4_7 = new JButton("");
		button4_7.setBackground(Color.WHITE);
		button4_7.setBounds(363, 396, 50, 50);
		frame.getContentPane().add(button4_7);
		button4_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][6] = button4_7;

		JButton button4_8 = new JButton("");
		button4_8.setBackground(Color.WHITE);
		button4_8.setBounds(413, 396, 50, 50);
		frame.getContentPane().add(button4_8);
		button4_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][7] = button4_8;

		JButton button4_9 = new JButton("");
		button4_9.setBackground(Color.WHITE);
		button4_9.setBounds(463, 396, 50, 50);
		frame.getContentPane().add(button4_9);
		button4_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[3][8] = button4_9;

		// Reihe 5
		JButton button5_1 = new JButton("");
		button5_1.setBackground(Color.WHITE);
		button5_1.setBounds(57, 447, 50, 50);
		frame.getContentPane().add(button5_1);
		button5_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][0] = button5_1;

		JButton button5_2 = new JButton("");
		button5_2.setBackground(Color.WHITE);
		button5_2.setBounds(108, 447, 50, 50);
		frame.getContentPane().add(button5_2);
		button5_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][1] = button5_2;

		JButton button5_3 = new JButton("");
		button5_3.setBackground(Color.WHITE);
		button5_3.setBounds(157, 447, 50, 50);
		frame.getContentPane().add(button5_3);
		button5_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][2] = button5_3;

		JButton button5_4 = new JButton("");
		button5_4.setBackground(Color.WHITE);
		button5_4.setBounds(210, 447, 50, 50);
		frame.getContentPane().add(button5_4);
		button5_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][3] = button5_4;

		JButton button5_5 = new JButton("");
		button5_5.setBackground(Color.WHITE);
		button5_5.setBounds(260, 447, 50, 50);
		frame.getContentPane().add(button5_5);
		button5_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][4] = button5_5;

		JButton button5_6 = new JButton("");
		button5_6.setBackground(Color.WHITE);
		button5_6.setBounds(310, 447, 50, 50);
		frame.getContentPane().add(button5_6);
		button5_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][5] = button5_6;

		JButton button5_7 = new JButton("");
		button5_7.setBackground(Color.WHITE);
		button5_7.setBounds(363, 447, 50, 50);
		frame.getContentPane().add(button5_7);
		button5_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][6] = button5_7;

		JButton button5_8 = new JButton("");
		button5_8.setBackground(Color.WHITE);
		button5_8.setBounds(413, 447, 50, 50);
		frame.getContentPane().add(button5_8);
		button5_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][7] = button5_8;

		JButton button5_9 = new JButton("");
		button5_9.setBackground(Color.WHITE);
		button5_9.setBounds(463, 447, 50, 50);
		frame.getContentPane().add(button5_9);
		button5_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[4][8] = button5_9;

		// Reihe 6
		JButton button6_1 = new JButton("");
		button6_1.setBackground(Color.WHITE);
		button6_1.setBounds(57, 497, 50, 50);
		frame.getContentPane().add(button6_1);
		button6_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][0] = button6_1;

		JButton button6_2 = new JButton("");
		button6_2.setBackground(Color.WHITE);
		button6_2.setBounds(108, 497, 50, 50);
		frame.getContentPane().add(button6_2);
		button6_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][1] = button6_2;

		JButton button6_3 = new JButton("");
		button6_3.setBackground(Color.WHITE);
		button6_3.setBounds(157, 497, 50, 50);
		frame.getContentPane().add(button6_3);
		button6_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][2] = button6_3;

		JButton button6_4 = new JButton("");
		button6_4.setBackground(Color.WHITE);
		button6_4.setBounds(210, 497, 50, 50);
		frame.getContentPane().add(button6_4);
		button6_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][3] = button6_4;

		JButton button6_5 = new JButton("");
		button6_5.setBackground(Color.WHITE);
		button6_5.setBounds(260, 497, 50, 50);
		frame.getContentPane().add(button6_5);
		button6_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][4] = button6_5;

		JButton button6_6 = new JButton("");
		button6_6.setBackground(Color.WHITE);
		button6_6.setBounds(310, 497, 50, 50);
		frame.getContentPane().add(button6_6);
		button6_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][5] = button6_6;

		JButton button6_7 = new JButton("");
		button6_7.setBackground(Color.WHITE);
		button6_7.setBounds(363, 497, 50, 50);
		frame.getContentPane().add(button6_7);
		button6_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][6] = button6_7;

		JButton button6_8 = new JButton("");
		button6_8.setBackground(Color.WHITE);
		button6_8.setBounds(413, 497, 50, 50);
		frame.getContentPane().add(button6_8);
		button6_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][7] = button6_8;

		JButton button6_9 = new JButton("");
		button6_9.setBackground(Color.WHITE);
		button6_9.setBounds(463, 497, 50, 50);
		frame.getContentPane().add(button6_9);
		button6_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[5][8] = button6_9;

		// Reihe 7
		JButton button7_1 = new JButton("");
		button7_1.setBackground(Color.WHITE);
		button7_1.setBounds(57, 550, 50, 50);
		frame.getContentPane().add(button7_1);
		button7_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][0] = button7_1;

		JButton button7_2 = new JButton("");
		button7_2.setBackground(Color.WHITE);
		button7_2.setBounds(108, 550, 50, 50);
		frame.getContentPane().add(button7_2);
		button7_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][1] = button7_2;

		JButton button7_3 = new JButton("");
		button7_3.setBackground(Color.WHITE);
		button7_3.setBounds(157, 550, 50, 50);
		frame.getContentPane().add(button7_3);
		button7_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][2] = button7_3;

		JButton button7_4 = new JButton("");
		button7_4.setBackground(Color.WHITE);
		button7_4.setBounds(210, 550, 50, 50);
		frame.getContentPane().add(button7_4);
		button7_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][3] = button7_4;

		JButton button7_5 = new JButton("");
		button7_5.setBackground(Color.WHITE);
		button7_5.setBounds(260, 550, 50, 50);
		frame.getContentPane().add(button7_5);
		button7_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][4] = button7_5;

		JButton button7_6 = new JButton("");
		button7_6.setBackground(Color.WHITE);
		button7_6.setBounds(310, 550, 50, 50);
		frame.getContentPane().add(button7_6);
		button7_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][5] = button7_6;

		JButton button7_7 = new JButton("");
		button7_7.setBackground(Color.WHITE);
		button7_7.setBounds(363, 550, 50, 50);
		frame.getContentPane().add(button7_7);
		button7_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][6] = button7_7;

		JButton button7_8 = new JButton("");
		button7_8.setBackground(Color.WHITE);
		button7_8.setBounds(413, 550, 50, 50);
		frame.getContentPane().add(button7_8);
		button7_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][7] = button7_8;

		JButton button7_9 = new JButton("");
		button7_9.setBackground(Color.WHITE);
		button7_9.setBounds(463, 550, 50, 50);
		frame.getContentPane().add(button7_9);
		button7_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[6][8] = button7_9;

		// Reihe 8
		JButton button8_1 = new JButton("");
		button8_1.setBackground(Color.WHITE);
		button8_1.setBounds(57, 601, 50, 50);
		frame.getContentPane().add(button8_1);
		button8_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][0] = button8_1;

		JButton button8_2 = new JButton("");
		button8_2.setBackground(Color.WHITE);
		button8_2.setBounds(108, 601, 50, 50);
		frame.getContentPane().add(button8_2);
		button8_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][1] = button8_2;

		JButton button8_3 = new JButton("");
		button8_3.setBackground(Color.WHITE);
		button8_3.setBounds(157, 601, 50, 50);
		frame.getContentPane().add(button8_3);
		button8_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][2] = button8_3;

		JButton button8_4 = new JButton("");
		button8_4.setBackground(Color.WHITE);
		button8_4.setBounds(210, 601, 50, 50);
		frame.getContentPane().add(button8_4);
		button8_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][3] = button8_4;

		JButton button8_5 = new JButton("");
		button8_5.setBackground(Color.WHITE);
		button8_5.setBounds(260, 601, 50, 50);
		frame.getContentPane().add(button8_5);
		button8_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][4] = button8_5;

		JButton button8_6 = new JButton("");
		button8_6.setBackground(Color.WHITE);
		button8_6.setBounds(310, 601, 50, 50);
		frame.getContentPane().add(button8_6);
		button8_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][5] = button8_6;

		JButton button8_7 = new JButton("");
		button8_7.setBackground(Color.WHITE);
		button8_7.setBounds(363, 601, 50, 50);
		frame.getContentPane().add(button8_7);
		button8_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][6] = button8_7;

		JButton button8_8 = new JButton("");
		button8_8.setBackground(Color.WHITE);
		button8_8.setBounds(413, 601, 50, 50);
		frame.getContentPane().add(button8_8);
		button8_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][7] = button8_8;

		JButton button8_9 = new JButton("");
		button8_9.setBackground(Color.WHITE);
		button8_9.setBounds(463, 601, 50, 50);
		frame.getContentPane().add(button8_9);
		button8_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[7][8] = button8_9;

		// Reihe 9
		JButton button9_1 = new JButton("");
		button9_1.setBackground(Color.WHITE);
		button9_1.setBounds(57, 651, 50, 50);
		frame.getContentPane().add(button9_1);
		button9_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][0] = button9_1;

		JButton button9_2 = new JButton("");
		button9_2.setBackground(Color.WHITE);
		button9_2.setBounds(108, 651, 50, 50);
		frame.getContentPane().add(button9_2);
		button9_2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][1] = button9_2;

		JButton button9_3 = new JButton("");
		button9_3.setBackground(Color.WHITE);
		button9_3.setBounds(157, 651, 50, 50);
		frame.getContentPane().add(button9_3);
		button9_3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][2] = button9_3;

		JButton button9_4 = new JButton("");
		button9_4.setBackground(Color.WHITE);
		button9_4.setBounds(210, 651, 50, 50);
		frame.getContentPane().add(button9_4);
		button9_4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][3] = button9_4;

		JButton button9_5 = new JButton("");
		button9_5.setBackground(Color.WHITE);
		button9_5.setBounds(260, 651, 50, 50);
		frame.getContentPane().add(button9_5);
		button9_5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][4] = button9_5;

		JButton button9_6 = new JButton("");
		button9_6.setBackground(Color.WHITE);
		button9_6.setBounds(310, 651, 50, 50);
		frame.getContentPane().add(button9_6);
		button9_6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][5] = button9_6;

		JButton button9_7 = new JButton("");
		button9_7.setBackground(Color.WHITE);
		button9_7.setBounds(363, 651, 50, 50);
		frame.getContentPane().add(button9_7);
		button9_7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][6] = button9_7;

		JButton button9_8 = new JButton("");
		button9_8.setBackground(Color.WHITE);
		button9_8.setBounds(413, 651, 50, 50);
		frame.getContentPane().add(button9_8);
		button9_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][7] = button9_8;

		JButton button9_9 = new JButton("");
		button9_9.setBackground(Color.WHITE);
		button9_9.setBounds(463, 651, 50, 50);
		frame.getContentPane().add(button9_9);
		button9_9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		btnFeld[8][8] = button9_9;

		for (byte byteZeile = 0; byteZeile < 9; byteZeile++) {
			for (byte byteSpalte = 0; byteSpalte < 9; byteSpalte++) {
				final byte byteFinalZeile = byteZeile;
				final byte byteFinalSpalte = byteSpalte;
				btnFeld[byteZeile][byteSpalte]
						.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								byteSpaltenWert = byteFinalSpalte;
								byteZeilenWert = byteFinalZeile;
								try {
									Clip clip = AudioSystem.getClip();
									AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(GrundGUI.class
											.getResourceAsStream(stoneClickSound));
									clip.open(audioInputStream);
									clip.start();
									audioInputStream.close();
								} catch (Exception exception) {
									System.err.println(exception.getMessage());
								}
							}
						});
			}
		}

		// Buttons f�r Zahlen einf�gen
		JButton buttonZahl1 = new JButton("1");
		buttonZahl1.setBackground(Color.WHITE);
		buttonZahl1.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl1.setBounds(600, 459, 50, 50);
		frame.getContentPane().add(buttonZahl1);
		btnZahlen[0] = buttonZahl1;

		JButton buttonZahl2 = new JButton("2");
		buttonZahl2.setBackground(Color.WHITE);
		buttonZahl2.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl2.setBounds(662, 459, 50, 50);
		frame.getContentPane().add(buttonZahl2);
		btnZahlen[1] = buttonZahl2;

		JButton buttonZahl3 = new JButton("3");
		buttonZahl3.setBackground(Color.WHITE);
		buttonZahl3.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl3.setBounds(724, 459, 50, 50);
		frame.getContentPane().add(buttonZahl3);
		btnZahlen[2] = buttonZahl3;

		JButton buttonZahl4 = new JButton("4");
		buttonZahl4.setBackground(Color.WHITE);
		buttonZahl4.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl4.setBounds(602, 521, 50, 50);
		frame.getContentPane().add(buttonZahl4);
		btnZahlen[3] = buttonZahl4;

		JButton buttonZahl5 = new JButton("5");
		buttonZahl5.setBackground(Color.WHITE);
		buttonZahl5.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl5.setBounds(662, 521, 50, 50);
		frame.getContentPane().add(buttonZahl5);
		btnZahlen[4] = buttonZahl5;

		JButton buttonZahl6 = new JButton("6");
		buttonZahl6.setBackground(Color.WHITE);
		buttonZahl6.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl6.setBounds(724, 521, 50, 50);
		frame.getContentPane().add(buttonZahl6);
		btnZahlen[5] = buttonZahl6;

		JButton buttonZahl7 = new JButton("7");
		buttonZahl7.setBackground(Color.WHITE);
		buttonZahl7.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl7.setBounds(600, 583, 50, 50);
		frame.getContentPane().add(buttonZahl7);
		btnZahlen[6] = buttonZahl7;

		JButton buttonZahl8 = new JButton("8");
		buttonZahl8.setBackground(Color.WHITE);
		buttonZahl8.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl8.setBounds(662, 583, 50, 50);
		frame.getContentPane().add(buttonZahl8);
		btnZahlen[7] = buttonZahl8;

		JButton buttonZahl9 = new JButton("9");
		buttonZahl9.setBackground(Color.WHITE);
		buttonZahl9.setFont(new Font("Tahoma", Font.PLAIN, 25));
		buttonZahl9.setBounds(724, 583, 50, 50);
		frame.getContentPane().add(buttonZahl9);
		btnZahlen[8] = buttonZahl9;

		// Zuweisen der Eintragemethode an das Zahlenfeld
		for (byte byteZaehler = 0; byteZaehler < 9; byteZaehler++) {
			final byte byteFinalEingabe = (byte) (byteZaehler + 1);
			btnZahlen[byteZaehler].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

					switch (aufgabe) {
					case 1:
						if (btnFeld[byteZeilenWert][byteSpaltenWert].getText() == "" && byteZeilenWert == 0) {
							sudoku.byteSudokuFeld[byteZeilenWert][byteSpaltenWert]=byteFinalEingabe;
							if (sudoku.pruefeRichtigkeit()==true){
								btnFeld[byteZeilenWert][byteSpaltenWert].setText(byteFinalEingabe + "");
								btnFeld[byteZeilenWert][byteSpaltenWert].setBackground(Color.WHITE);
								gibWonSoundAus();
								buttonWeiter.setEnabled(true);
							}
						}
						break;
						
					case 2:
						if (btnFeld[byteZeilenWert][byteSpaltenWert].getText() == "" && byteSpaltenWert == 0) {
							sudoku.byteSudokuFeld[byteZeilenWert][byteSpaltenWert]=byteFinalEingabe;
							if (sudoku.pruefeRichtigkeit()==true){
								btnFeld[byteZeilenWert][byteSpaltenWert].setText(byteFinalEingabe + "");
								btnFeld[byteZeilenWert][byteSpaltenWert].setBackground(Color.WHITE);
								buttonWeiter.setEnabled(true);
								gibWonSoundAus();
							}
						}
						break;
						
					case 3:
						if (btnFeld[byteZeilenWert][byteSpaltenWert].getText() == "" && byteZeilenWert <= 2 && byteSpaltenWert <= 2) {
							sudoku.byteSudokuFeld[byteZeilenWert][byteSpaltenWert]=byteFinalEingabe;
							if (sudoku.pruefeRichtigkeit()==true){
								btnFeld[byteZeilenWert][byteSpaltenWert].setText(byteFinalEingabe + "");
								btnFeld[byteZeilenWert][byteSpaltenWert].setBackground(Color.WHITE);
								buttonWeiter.setEnabled(true);
								gibWonSoundAus();
							}
						}
						break;
						
					case 4:
						if (btnFeld[byteZeilenWert][byteSpaltenWert].getText() == "") {
							sudoku.byteSudokuFeld[byteZeilenWert][byteSpaltenWert]=byteFinalEingabe;
							if (sudoku.pruefeRichtigkeit()==true){
								btnFeld[byteZeilenWert][byteSpaltenWert].setText(byteFinalEingabe + "");
								btnFeld[byteZeilenWert][byteSpaltenWert].setBackground(Color.WHITE);
								buttonWeiter.setEnabled(true);
								gibWonSoundAus();
							}
						}
						break;

					default:
						break;
					}

				}
			});
		}

		// Button um die Farbe in Grün zu ändern
		JButton btnGruen = new JButton("");
		btnGruen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.getContentPane().setBackground(new Color(153, 204, 51));
			}
		});
		btnGruen.setBackground(new Color(153, 204, 51));
		btnGruen.setBounds(961, 471, 40, 40);
		frame.getContentPane().add(btnGruen);

		// Button um die Farbe in Blau zu ändern
		JButton btnBlau = new JButton("");
		btnBlau.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.getContentPane().setBackground(new Color(0, 153, 204));

			}
		});
		btnBlau.setBackground(new Color(0, 153, 204));
		btnBlau.setBounds(909, 420, 40, 40);
		frame.getContentPane().add(btnBlau);

		// Button um die Farbe in Gelb zu ändern
		JButton btnGelb = new JButton("");
		btnGelb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.getContentPane().setBackground(new Color(255, 215, 0));
			}
		});
		btnGelb.setBackground(new Color(255, 215, 0));
		btnGelb.setBounds(961, 420, 40, 40);
		frame.getContentPane().add(btnGelb);

		// Button um die Farbe in Pink zu ändern
		JButton btnPink = new JButton("");
		btnPink.setBackground(new Color(255, 153, 255));
		btnPink.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.getContentPane().setBackground(new Color(255, 153, 255));
			}
		});
		btnPink.setBounds(909, 522, 40, 40);
		frame.getContentPane().add(btnPink);

		// Button um die Farbe in Meeresgrün zu ändern
		JButton btnMeeresGruen = new JButton("");
		btnMeeresGruen.setBackground(new Color(102, 153, 153));
		btnMeeresGruen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.getContentPane().setBackground(new Color(102, 153, 153));
			}
		});
		btnMeeresGruen.setBounds(961, 522, 40, 40);
		frame.getContentPane().add(btnMeeresGruen);

		// Button um die Farbe in Rot zu ändern
		JButton btnRot = new JButton("");
		btnRot.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.getContentPane().setBackground(new Color(204, 0, 0));
			}
		});
		btnRot.setBackground(new Color(204, 0, 0));
		btnRot.setBounds(909, 471, 40, 40);
		frame.getContentPane().add(btnRot);

		// Buttonweiter
		buttonWeiter.setBounds(884, 636, 125, 74);
		frame.getContentPane().add(buttonWeiter);
		buttonWeiter.setBackground(Color.WHITE);
		buttonWeiter.setForeground(Color.WHITE);
		buttonWeiter.setFont(new Font("Tahoma", Font.PLAIN, 15));
		buttonWeiter.setContentAreaFilled(false);
		buttonWeiter.setBorderPainted(false);
		buttonWeiter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// Einen Schritt weiterzur�ck gehen in der Erkl�rung
				intPosition = intPosition + 1;
				ausgeben(intPosition);
			}
		});

		// Zur�ckbutton
		buttonZurueck.setBounds(734, 636, 125, 74);
		frame.getContentPane().add(buttonZurueck);
		buttonZurueck.setForeground(Color.WHITE);
		buttonZurueck.setBackground(Color.WHITE);
		buttonZurueck.setFont(new Font("Tahoma", Font.PLAIN, 15));
		buttonZurueck.setContentAreaFilled(false);
		buttonZurueck.setBorderPainted(false);
		buttonZurueck.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (intPosition != 0) {
					intPosition = intPosition - 1;
					ausgeben(intPosition);
				}
				beendeAufgabe();
			}
		});

		// Endebutton
		buttonEnde.setBounds(884, 11, 92, 74);
		buttonEnde.setIcon(new ImageIcon(Tutorial.class
				.getResource("/Bilder/SudokuEnde.gif")));
		buttonEnde.setFont(new Font("Tahoma", Font.PLAIN, 15));
		buttonEnde.setContentAreaFilled(false);
		buttonEnde.setBorderPainted(false);
		frame.getContentPane().add(buttonEnde);

		// Bild des Sudokufelds einf�gen
		JLabel labelSudokuFeld = new JLabel("");
		labelSudokuFeld.setIcon(new ImageIcon(GrundGUI.class
				.getResource("/Bilder/SudokuFeld.gif")));
		frame.getContentPane().add(labelSudokuFeld);
		labelSudokuFeld.setBounds(-47, 196, 643, 514);
		buttonEnde.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// Schlie�en �ber Button
				Startfenster startfenster = new Startfenster();
				startfenster.getJFrame().getContentPane()
						.setBackground(frame.getContentPane().getBackground());
				frame.dispose();
			}
		});

		ausgeben(intPosition);
		macheZahlenNichtKlickbar();

	}

	public void ausgeben(Integer pos) {
		switch (pos) {
		case 0:
			// gibt die Startseite aus
			labelText
					.setText("<html><body>Du bist auf der Startseite. <br> Willkommen beim Tutorial! <br><br> Hier lernst du wie man Sudoku spielt!</body></html>");
			buttonZurueck.setVisible(false);
			break;
		case 1:
			// gibt die erste Seite aus;
			leereButtons();
			labelText
					.setText("<html><body>In diesem Spiel geht es um die Zahlen 1 bis 9. <br> Diese Zahlen musst du in die leeren Pl&auml;tze in einem Feld eintragen. <br> Nach welchen Regeln du das machen musst, erkl&auml;re ich dir jetzt.</body></html>");
			buttonZurueck.setVisible(true);
			break;
		case 2:
			// gibt die zweite Seite aus;
			// Beispiel: Zeile mit einem freien Feld
			leereButtons();
			labelText
					.setText("<html><body>In jeder Zeile des Feldes darf jede Zahl nur genau einmal vorkommen. <br> Welche Zahl muss in die L&uuml;cke in diesem Beispiel? <br> <br> W&auml;hle zuerst das leere Feld aus und klicke dann auf die passende Zahl für diese L&uuml;cke. </body></html>");
			uebenZeile();
			break;
		case 3:
			// gibt die dritte Seite aus;
			// Beispiel: Spalte mit einem freien Feld
			leereButtons();
			labelText
					.setText("<html><body>Das gleiche gilt f&uuml;r jede Spalte. <br> Welche Zahl muss in diese L&uuml;cke? <br> <br> W&auml;hle wieder erst das leere Feld aus und dann die passende Zahl.</body></html>");
			uebenSpalte();
			break;
		case 4:
			// Beispiel: 3x3 Feld mit einer leeren Stelle
			leereButtons();
			labelText
					.setText("<html><body>Es gibt auch noch kleine Felder in dem gro&szlig;en Feld. <br> In den kleinen Felder d&uuml;rfen auch alle Zahlen von 1 bis 9 nur einmal vorkommen. <br> <br> W&auml;hle wieder zuerst das leere Feld aus und dann die Zahl, die dort hin soll. </body></html>");
			uebenKleinesFeld();
			break;
		case 5:
			// Extra ja/nein Auswahl?
			leereButtons();
			labelText
					.setText("<html><body>Hast du bist jetzt alles verstanden? <br> Dann tun wir jetzt alle Regeln zusammen.</body></html>");
			break;
		case 6:
			// Sudokufeld mit 2 freien Feldern einf�gen
			leereButtons();
			labelText
					.setText("<html><body>Hier siehst du ein richtiges Sudoku Feld. Es fehlen 2 Zahlen. <br> Kannst du mit den Regeln herausfinden welche? <br> <br> Klicke jeweils erst auf eine der Lücken und dann auf die passende Zahl.</body></html>");
			uebenGrossesFeld();
			buttonWeiter.setVisible(true);
			break;
		case 7:
			leereButtons();
			labelText
					.setText("<html><body>Das war super! <br> Damit ist die Erkl&auml;rung zu Ende.<br> Du kannst das Tutorial jederzeit wieder starten. <br> Viel Spa&szlig; beim Spielen! </body></html>");
			buttonWeiter.setVisible(false);
			break;
		default:
			labelText.setText("Seite " + pos
					+ " befindet sich nicht im Tutorial");
		}
		;
	}

	public void starteAufgabe() {
		buttonWeiter.setEnabled(false);
		macheZahlenKlickbar();
		arrayGeweahlt[0] = 0;
		arrayGeweahlt[1] = 0;
		if (aufgabe == 4) {
			luechenInGrFeld = 2;
		}
	}

	public void beendeAufgabe() {
		buttonWeiter.setEnabled(true);
		macheZahlenNichtKlickbar();
		if (aufgabe == 4) {
			//
		}

	}

	public void erstelleSudoku() {
		sudoku = new Sudoku();
		sudoku.erstelleLeeresFeld();
		SudokuGenerator generator = new SudokuGenerator(sudoku);
		generator.initialisiereZufallsSudoku();
		SudokuLoeser loeser = new SudokuLoeser(generator.getSudoku());
		loeser.loeseMitBacktracking();
		sudoku = loeser.getSudoku();
	}
	
	
	public void gibFeldAus(int iZeilenBegrenzung, int iSpaltenBegrenzung) {
		for (int i=0; i<iZeilenBegrenzung; i++) {
			for (int j=0; j<iSpaltenBegrenzung; j++) {
				if (sudoku.byteSudokuFeld[i][j]==0) {
					btnFeld[i][j].setText("");
					btnFeld[i][j].setBackground(new Color(253, 198, 137));
				}
				else {
					btnFeld[i][j].setText("" + sudoku.byteSudokuFeld[i][j]);
				}
			}
		}
	}
	
	public void gibWonSoundAus() {
		try {
			Clip clip = AudioSystem.getClip();
			AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(GrundGUI.class
					.getResourceAsStream(wonGame));
			clip.open(audioInputStream);
			clip.start();
			audioInputStream.close();
		} catch (Exception exception) {
			System.err.println(exception.getMessage());
		}
	}
	
	public void uebenZeile() {
		erstelleSudoku();
		sudoku.byteSudokuFeld[0][3]=0;
		gibFeldAus(1, 9);
		aufgabe = 1;
		starteAufgabe();
	}

	public void uebenSpalte() {
		erstelleSudoku();
		sudoku.byteSudokuFeld[5][0]=0;
		gibFeldAus(9, 1);
		aufgabe = 2;
		starteAufgabe();
	}

	public void uebenKleinesFeld() {
		erstelleSudoku();
		sudoku.byteSudokuFeld[2][2]=0;
		gibFeldAus(3, 3);
		aufgabe = 3;
		starteAufgabe();
	}

	public void uebenGrossesFeld() {
		erstelleSudoku();
		sudoku.byteSudokuFeld[7][6]=0;
		gibFeldAus(9, 9);
		aufgabe = 4;
		starteAufgabe();
	}

	
	public void leereButtons() {
		for (byte i = 0; i <= 8; i++) {
			for (byte j = 0; j <= 8; j++) {
				btnFeld[i][j].setText("");
				btnFeld[i][j].setBackground(Color.WHITE);
			}
		}
	}

	public void macheZahlenKlickbar() {
		for (int i = 0; i <= 8; i++) {
			btnZahlen[i].setEnabled(true);
		}
	}

	public void macheZahlenNichtKlickbar() {
		for (int i = 0; i <= 8; i++) {
			btnZahlen[i].setEnabled(false);
		}
	}
}
